//
//  LuckyNotifyWnd.m
//  SMTools
//
//  Created by fengsh on 2019/1/5.
//  Copyright © 2019 fengsh. All rights reserved.
//

#import "LuckyNotifyWnd.h"
#import <Masonry/Masonry.h>
#import "LuckyItem.h"
#import "LuckyApi.h"

@interface LuckyNotifyWnd ()<NSCollectionViewDelegate,NSCollectionViewDataSource>
@property (weak) IBOutlet NSImageView *bg_icon;
@property (weak) IBOutlet NSImageView *icon;
@property (weak) IBOutlet NSCollectionView *collectionview;
@property (weak) IBOutlet NSScrollView *scrollview;
@property (weak) IBOutlet NSTextField *lb_title;
@property (weak) IBOutlet NSView *lv;
@property (weak) IBOutlet NSTextField *left_line;
@property (weak) IBOutlet NSTextField *right_line;

@end

@implementation LuckyNotifyWnd

- (void)windowDidLoad {
    [super windowDidLoad];
    
    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
    NSImage *img = [NSImage imageNamed:@"img_back4_1"];
    [self.lb_title setStringValue:self.currentProject.prize_level_name?:@""];
    self.lb_title.font = [NSFont systemFontOfSize:30];
    self.lb_title.textColor = [NSColor whiteColor];
    self.left_line.textColor = [NSColor whiteColor];
    [self.left_line setWantsLayer:YES];
    self.left_line.layer.backgroundColor = [NSColor whiteColor].CGColor;
    
    self.right_line.textColor = [NSColor whiteColor];
    [self.right_line setWantsLayer:YES];
    self.right_line.layer.backgroundColor = [NSColor whiteColor].CGColor;
    
    ///去背景色
    [self.scrollview setDrawsBackground:NO];
    self.scrollview.backgroundColor = [NSColor clearColor];
    
    [self.scrollview setHasVerticalScroller:NO];
    [self.scrollview setHasHorizontalScroller:NO];

//    [self.scrollview setScrollerStyle:NSScrollerStyleOverlay];
    ///去背景色
    [self.collectionview setBackgroundColors:@[[NSColor clearColor]]];
    
    [self layoutUI];
    
    self.bg_icon.image = img;
    
    

//    NSArray *arr = @[
//                     @{@"itemTitle":@"Product 1",
//                       @"itemDescription":@"Product 1 Description",
//                       @"itemDetailedDescription":@"128 Ratings",
//                       @"itemPrice":@"$20.90",
//                       @"itemImage":@"PastedGraphic-1.png"},
//
//                     @{@"itemTitle":@"Product 2",
//                       @"itemDescription":@"Product 2 Description",
//                       @"itemDetailedDescription":@"128 Ratings",
//                       @"itemPrice":@"$10.90",
//                       @"itemImage":@"PastedGraphic-3.png"},
//
//                     @{@"itemTitle":@"Product 3",
//                       @"itemDescription":@"Product 3 Description",
//                       @"itemDetailedDescription":@"128 Ratings",
//                       @"itemPrice":@"$9810.90",
//                       @"itemImage":@"PastedGraphic-4.png"},
//
//                     @{@"itemTitle":@"Product 4",
//                       @"itemDescription":@"Some New Description",
//                       @"itemDetailedDescription":@"128 Ratings",
//                       @"itemPrice":@"$100.90",
//                       @"itemImage":@"PastedGraphic-5.png"},
//
//                     @{@"itemTitle":@"Product 5",
//                       @"itemDescription":@"This product rocks",
//                       @"itemDetailedDescription":@"128 Ratings",
//                       @"itemPrice":@"$109.19",
//                       @"itemImage":@"PastedGraphic-1.png"},
//
//                     @{@"itemTitle":@"Product 6",
//                       @"itemDescription":@"This product is for new users",
//                       @"itemDetailedDescription":@"128 Ratings",
//                       @"itemPrice":@"$910.90",
//                       @"itemImage":@"PastedGraphic-6.png"},
//
//                     @{@"itemTitle":@"Product 7",
//                       @"itemDescription":@"The best we have built so far",
//                       @"itemDetailedDescription":@"128 Ratings",
//                       @"itemPrice":@"$632.90",
//                       @"itemImage":@"PastedGraphic-7.png"},
//
//                     ];
    
    ///mac就是一傻B，用nib创建不起来，要用new。
    LuckyItem *item = [LuckyItem new];
    [self.collectionview setItemPrototype:item];
    [self.collectionview setContent:self.results];
    
    if (self.results.count > 5) {
        ///水平滚动
//        [self.scrollview setHasHorizontalScroller:YES];
        ///竖直滚动
        [self.scrollview setHasVerticalScroller:YES];
    }

}

- (void)layoutUI
{
    float scale = [NSScreen mainScreen].backingScaleFactor;
//    [self.window setContentSize:CGSizeMake(4000 * 1 / scale, (4000 * 1 / scale) * 1.0 / 3.0)];
    float w = CGRectGetWidth([NSScreen mainScreen].frame);
    [self.window setContentSize:CGSizeMake(w*0.8, w*0.8*0.25)];
    
    float itemw = 240;
    float itemh = 240;
    
    float count = MIN(5,self.results.count);
    float sv_w = count * itemw + 20; //有滚动条时加20
    //2倍图
    [self.bg_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(@(0));
        make.width.equalTo(@(2000));
        make.height.equalTo(self.bg_icon.mas_width).multipliedBy(0.25);
    }];
    
    [self.scrollview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(@(0));
        make.centerY.equalTo(@(50));
        make.width.equalTo(@(sv_w));
        make.height.equalTo(@(itemh));
    }];
    
    [self.lv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(@(0));
        make.width.equalTo(@(400));
        make.height.equalTo(@(40));
        make.top.equalTo(@(30));
    }];
    
    [self.lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(@(0));
        make.height.equalTo(@(50));
        make.width.greaterThanOrEqualTo(@(40));
    }];
    
    [self.left_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.lb_title.mas_leading).offset(-20);
        make.centerY.equalTo(@(0));
        make.height.equalTo(@(1));
        make.width.equalTo(@(80));
    }];
    
    [self.right_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.lb_title.mas_trailing).offset(20);
        make.centerY.equalTo(@(0));
        make.height.equalTo(@(1));
        make.width.equalTo(@(80));
    }];
}

@end
